﻿using System;
using System.Collections.Generic;
using System.Text;

namespace xReplace
{
    class AppendCommand : AbstractProcessingCommand
    {
        public AppendCommand(ref Content pipes)
            : base(ref pipes)
        { }

        public override bool ProcessCommand(System.Xml.XmlNodeList param)
        {
            string fromlabel = this.GetNodeValue("fromlabel", param);
            string value = this.GetNodeValue("value", param);
            if (GetNodeAttributeAsBoolean("value", "escape", param))
                value = SpecialCharHelper.Unescape(value);

            if (fromlabel != "") value = this.contentPipelines.LoadContent(fromlabel);

            string tolabel = this.GetNodeValue("tolabel", param);
            if (tolabel == "")
            {
                this.contentPipelines.DefaultContent = this.contentPipelines.DefaultContent + value;
            }
            else
            {
                string tmp = this.contentPipelines.LoadContent(tolabel);
                this.contentPipelines.StoreContent(tolabel, tmp + value);
            }
            return true;
        }
    }
}
